using Headspring.Training.DependencyResolution;
using Headspring.Training.Infrastructure;
using NHibernate;
using NHibernate.Tool.hbm2ddl;
using NUnit.Framework;
using StructureMap;

namespace Headspring.Training.IntegrationTests
{
	[TestFixture]
	public class TestHelper
	{
		[Test, Explicit]
		public void DoRecreate()
		{
			new DependencyRegistrar().RegisterDependencies();
			RecreateDatabase();
		}

		public static void RecreateDatabase()
		{
			ISessionBuilder sessionBuilder = getSessionBuilder();
			var exporter = new SchemaExport(sessionBuilder.GetConfiguration());
			exporter.Execute(true, true, false, true);
		}

		private static ISessionBuilder getSessionBuilder()
		{
			return ObjectFactory.GetInstance<ISessionBuilder>();
		}

		public static void ClearTables()
		{
			ISession session = getSessionBuilder().GetSession();
			session.Delete("from WorkOrder");
			session.Delete("from Employee");
			session.Flush();
		}
	}
}